package net.j4love.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author He Peng
 * @create 2017-08-05 23:09
 * @update 2017-08-05 23:09
 * @updatedesc : 更新说明
 * @see
 */
public class ForgeryAsyncIOEchoServer {

    public static void main(String[] args) throws IOException {
        new ForgeryAsyncIOEchoServer().start("127.0.0.1",8080);
    }

    public void start(String host,int port) throws IOException {
        ServerSocket serverSocket = new ServerSocket();
        serverSocket.bind(new InetSocketAddress(host,port));
        System.out.println("echo server started on " + host + ":" + port);
        for (;;) {
            Socket socket = serverSocket.accept();
            new Thread(new EchoServerHandler(socket),
                    "ForgeryAsyncIOEchoServerHandler-Thread").start();
        }
    }
}
